package top.lyjwn.todo.weinxin.api.bjnews;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.lyjwn.todo.weinxin.api.url.WXBjnewsUrl;
import top.lyjwn.todo.common.utils.http.HttpUtil;

/**
 * 获取access_token
 * access_token是公众号的全局唯一接口调用凭据，公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时，需定时刷新，重复获取将导致上次获取的access_token失效
 *
 * @author luoyujie
 */
@Component
public class GetBaseAccessToken {

    @Autowired
    private WXBjnewsUrl wxBjnewsUrl;

    public String getUrl() {
        String url = wxBjnewsUrl.getAPP_ACCESS_TOKEN();
        return url;
    }

    public String getResultString() {
        String result = HttpUtil.request(getUrl(), HttpUtil.METHOD_GET);
        return result;
    }

    public JSONObject getResultJSONObject()
    {
        String resultString = this.getResultString();
        return JSONObject.parseObject(resultString);
    }

}
